The OOP Paradigm
|
The OOP Paradigm
The need to program GUIs led to a distinct programming paradigm,
called object-oriented programming. An object-oriented programming system
(OOPS) consists of objects. An object comprises both data and algorithms. The
data describes the state of the object. Objects communicate by sending
messages to each other. When an object receives a message, it responds by
executing one of its algorithms. The algorithm may change the state of the
object, generate output, or send messages to other objects. OOPS are well-suited to programming GUIs. Typically, each element of a
GUI is represented by one object. The object determines both the state and
the behaviour of the corresponding element. For example, an object
representing a window would have data for its position, size and title. If
the user closes the window, the OOPS sends a message to the window object
telling it to close itself. The window then executes an algorithm that erases
its image from the screen. Objects are most important
in this style of programming. This contrasts with procedural languages that
focus on executing procedures in the computer. Here, you may think of
real-world objects such as people, cars, houses, and so on. Common
characteristics of these real-world objects are that they all have a state
and a behaviour. For example, people have state (name, length, weight, etc.)
and behaviour (talk, walk, sit, ...). Cars have state (speed, direction, fuel
consumption, ...) and behaviour (start, accelerate, brake, stop, turn, ...). In object-oriented
programming, a class is a programming language construct that is used as a
blueprint to create objects. This blueprint includes attributes and methods
that the created objects all share. In object-oriented
programming, inheritance is a way to form new classes (instances of which are
called objects) using classes that have already been defined. The inheritance
concept was invented in 1967 for Simula. Encapsulation is a process of binding or wrapping the data and the
codes that operates on the data into a single entity. This keeps the data
safe from outside interface and misuse. One way to think about encapsulation
is as a protective wrapper that prevents code and data from being arbitrarily
accessed by other code defined outside the wrapper. In computer science, the mechanism and practice of abstraction reduce
and factor out details so that one can focus on a few concepts at a time.
Abstraction can apply to control or to data: Control abstraction is the abstraction
of actions while data abstraction is that of data structures (e.g. datatypes
[vectors and pixels]). Data abstraction allows handling data bits in
meaningful ways. For example, it is the basic motivation behind datatype.
Object-oriented programming is an attempt to abstract both data and code. |